//
//  ZCXUserDetialViewController.m
//  LoveOfPet
//
//  Created by dllo on 15/11/16.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "ZCXUserDetialViewController.h"
#import "ZCXUserDetialTableViewCell.h"
#import "ZCXUserDetialView.h"
#import "ZFHYNetWork.h"
#import "ZCXUserDetial.h"
#import "ZCXUserPerDetialViewController.h"
#import <SVProgressHUD.h>
#define HEIGHT  [[UIScreen mainScreen]bounds].size.height / 667
#define WIDTH   [[UIScreen mainScreen]bounds].size.width / 375

@interface ZCXUserDetialViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) ZCXUserDetial *userDetial;
@end

@implementation ZCXUserDetialViewController
- (void)dealloc{
    [_tableView release];
    [_strID release];
    [_titleName release];
    [_userDetial release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人主页";
    self.view.backgroundColor = [UIColor whiteColor];
     self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 25 * WIDTH, 25 * HEIGHT);
    [button setBackgroundImage:[UIImage imageNamed:@"Zgeren1"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(pushToUserMessage:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    
    NSString *urlString = [self.titleName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    urlString  = [NSString stringWithFormat:@"http://newapi.meipai.com/users/show.json?id=%@&name=%@", self.strID, urlString];
    [self loadDataWithStrng:urlString];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 * HEIGHT) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.bounces = NO;
    _tableView.showsVerticalScrollIndicator = NO;
//    self.tableView.backgroundColor = [UIColor yellowColor];
    //注册Cell
    [_tableView registerClass:[ZCXUserDetialTableViewCell class] forCellReuseIdentifier:@"zcxuserdetialtableviewcell"];
    [self.view addSubview:_tableView];
    [_tableView release];
}
- (void)loadDataWithStrng:(NSString *)urlString{
    [ZFHYNetWork handleGETWithUrlString:urlString parameters:nil showHuD:YES onView:nil successfulBlock:^(id responseObject) {
        NSDictionary *dic = responseObject;
        self.userDetial = [ZCXUserDetial ZCXUserDetialWithDictionary:dic];
        [self.tableView reloadData];
    } failureBlock:^(NSError *error) {
        NSLog(@"失败");
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZCXUserDetialTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"zcxuserdetialtableviewcell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor purpleColor];
    cell.userDetial = _userDetial;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return self.view.frame.size.height;
}
- (void)pushToUserMessage:(UIButton *)button{
    if (self.userDetial == nil) {
        
    }else{
    ZCXUserPerDetialViewController *petDetial = [[ZCXUserPerDetialViewController alloc]init];
    petDetial.userDetial = self.userDetial;
    [self.navigationController pushViewController:petDetial animated:YES];
    [petDetial release];
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    [SVProgressHUD dismiss];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
